/*window.onloaded = function() {
	setTimeout(function(){
        $("#popupLoginSelect").popup("open");
   },1000);
}*/
(function () {
	$(document).ready(function() {
		/*jQuery('#loadingImage').hide();*/
		/*$("#popupLoginSelect").popup();
		$("#popupLoginSelect").popup('open');*/
		/*$("#goHome").attr("href",$("#goHome").attr("href")+"&&identify="+$('#identify').val());*/
		
		//$("#popupLoginSelectTrigger").trigger("click");
		var H = $(document).height();
		var div = $('#foot').height();
		$('#foot').attr('style','text-align:center; margin:0;  padding:0; width: 100%;  position: absolute; top: '+(H-div) +'px;');
	});
	$(window).resize(function() {
		var H = $(document).height();
		var div = $('#foot').height();
		$('#foot').attr('style','text-align:center; margin:0;  padding:0; width: 100%;  position: absolute; top: '+(H-div) +'px;');
	})
    ///用户登录
    jQuery('#subtnForUser').on('click', function () {
		    var name = jQuery("#user").val();
			var password =jQuery("#pwd").val();
			var smsCode =jQuery("#smsCode").val();
			var identify = jQuery("#identify").val();
			var urladress =jQuery("#url").val();
				var url = window.rootPath + '/ui/login/msubmit';
				jQuery("input").attr("disabled", true);
				jQuery(".login").attr("disabled", true);
				jQuery(".set").attr("disabled", true);
				
				if(_phoneType=="Android"){
					window.jump.proShow(); 
				}else if(_phoneType=="Ios"){
					window.webkit.messageHandlers.submitWaiting.postMessage({body: 'open'});
				}else{
					$("#popupWait").popup();
	        		$("#popupWait").popup('open');
				}
				
				/*jQuery('#loadingImage').show();*/
				var data = {
					"accountName" : name,
					"password" : sha256_digest(password),
					"smsCode" : smsCode
				}
				jQuery.ajax({
					url : encodeURI(url),
					type : "post",
					dataType : "json",
					data : JSON.stringify(data),
					contentType : "application/json;charset=UTF-8",
					success : function(data) {
						jQuery("input").attr("disabled", false);
						jQuery(".login").attr("disabled", false);
						jQuery(".set").attr("disabled", false);
						/*jQuery('#loadingImage').hide();*/
						if(_phoneType=="Android"){
							window.jump.proDismiss(); 
						}else if(_phoneType=="Ios"){
							window.webkit.messageHandlers.submitWaiting.postMessage({body: 'close'});
						}else{
							$("#popupWait").popup('close');
						}
						
						if (data.code == 0) {
							jQuery('#error').html('用户名或密码错误');
							/*createCode();
							jQuery("#loginCode").val('');*/
						} else if (data.code == 1) {							
							if(_phoneType=="Ios"){
								var d={
										"currentUserPwd":sha256_digest(password),
										"currentUserName":data.user.name
								}
								window.webkit.messageHandlers.updateUserInfo.postMessage({currentUserPwd:sha256_digest(password),
									currentUserName:data.user.name,currentAccountName:name});
							}else if(_phoneType=="Android"){
								window.jump.saveUserInfo(name,password);
							}
							/*var picture = data.picture;
							localStorage.setItem('picture', picture);
							localStorage.setItem('name', name);
							localStorage.setItem('userId', data.userId);	*/
							if(identify == null || typeof(identify) == undefined || identify == '' || identify == 'undefined' || identify=='null' ){
								if(urladress == ''){
									window.location.href = window.rootPath +"/ui/mobileMain?device=mobile&&identify="+identify;
								}else{
									if(urladress.indexOf("?") != -1){
										window.location.href = window.rootPath + urladress+"&device=mobile&&identify="+identify;
									}else{
										window.location.href = window.rootPath + urladress+"?device=mobile&&identify="+identify;
									}
								}
							}else{
								window.location.href = window.rootPath +"/ui/bussinessmain?device=mobile&&identify="+identify;
							}
						}
						else if (data.code == 3) {
						
							/*message(data.message);*/
						}
						else if(data.code == 99){//验证码失败
							/*jQuery('#error').html(data.message);*/
						}
					}
				});
    });
    
//    $(document).on("pagecreate","#pageOne",function(){   
//        setTimeout(function(){
//             $("#popupLoginSelect").popup("open");
//        },1000);
//    });
    
	//注册
    jQuery('#subtnForRegister').on('click', function () {
    		var url=window.rootPath+'/ui/mobileMain/register'+"?device=mobile&identify="+$("#identify").val();
    		window.location.href = url;
    });
})();